package tests.plotfunctions;


import java.awt.Color;

import org.junit.Test;

import ac.essex.graphing.charts.discrete.BarChartPlot;
import ac.essex.graphing.plotting.Graph;
import ac.essex.graphing.plotting.PlotSettings;
import ac.essex.graphing.swing.GraphApplication;


/**
 * Demonstrates how to display a graph using JavaPlot.
 *
 * <p>
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version,
 * provided that any use properly credits the author.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details at http://www.gnu.org
 * </p>
 *
 @author Olly Oechsle, University of Essex
 @version 1.0
 */
public class Demo {

	@Test
    public void testPlotChart() {

		new GraphApplication(getExampleGraph1());
    }
    
    @Test
    public void testPlotFunctions() {

    	new GraphApplication(getExampleGraph2());
    	while(true);
    }
   

    public static Graph getExampleGraph2() {

        PlotSettings p = new PlotSettings(0, 4, 3, 5);
        p.setPlotColor(Color.RED);
        p.setGridSpacingX(0.3);
        p.setGridSpacingY(0.3);
        p.setTitle("Funcion 1: sin(10x) * exp(-x) - 4");
        Graph graph = new Graph(p);
        graph.functions.add(new Funcion1());
        
        return graph;
    }
    
    public static Graph getExampleGraph1() {

        // Create some data
        String[] labels = new String[]{"Standard GP", "SGGP", "1 Layer MLP", "2 Layer MLP", "3 Layer MLP", "K-NN", "Adaboosted GA", "Kohonen NN"};
        double[] lows = new double[]{31.7,76.7,64.1,63.3,63.3,43.3,63.3,40.8};
        double[] high = new double[]{75.8,85.8,68.3,68.3,67.5,55.8,70.8,53.3};
        double[] means = new double[]{60.84,81.66,66.62,65.8,65.5,50.5,68.3,48.8};

        // All the graph settings are stored in this object.
        PlotSettings p = new PlotSettings();
        
        p.setMinX(0);
        p.setMinY(0);

        p.setMaxX(labels.length);
        p.setMaxY(100);

        p.setGridSpacingX(1);
        p.setGridSpacingY(10);

        // Set the title
        p.setTitle("Performance Comparison for the Pasta Experiment");

        // Create the graph object
        Graph graph = new Graph(p);

        // Add a CandleStick plot to the graph's function list
        graph.functions.add(new BarChartPlot(labels, high, means, lows));
        //graph.functions.add(new CandleStickPlot(labels, high, means, lows));

        return graph;

    }
}
